var cc__importDefault = __importDefault;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $GameEventType = require("GameEventType");
var $1$Loader = require("Loader");
var r = cc__importDefault($1$Loader);
var $1$EventManager = require("EventManager");
var a = cc__importDefault($1$EventManager);
var def_UIManager = function () {
  function _ctor() {}
  _ctor.init = function (t) {
    this.node = t;
    this.UIs = {};
    this.onEvents();
  };
  _ctor.onEvents = function () {
    a.default.on($GameEventType.EventType.UIEvent.enter, this.enterUI, this);
    a.default.on($GameEventType.EventType.UIEvent.exit, this.exitUI, this);
  };
  _ctor.getUI = function (t) {
    if (this.UIs[t]) {
      return this.UIs[t];
    } else {
      console.warn("UI尚未加载，无法获取：", t);
      return null;
    }
  };
  _ctor.enterUI = function (t, e) {
    var o = this.UIs[t];
    if (null !== o) {
      if (o) {
        this.showUI(t, e);
      } else {
        this.loadUI(t, e);
      }
    }
  };
  _ctor.showUI = function (t, e) {
    var o = this.UIs[t];
    if (o) {
      o.show(e);
      a.default.emit($GameEventType.EventType.UIEvent.entered, t);
    }
  };
  _ctor.loadUI = function (t, e) {
    var o = this;
    var n = cc.find("Canvas").getComponentInChildren(t);
    if (n) {
      this.UIs[t] = n;
      this.showUI(t, e);
    } else {
      r.default.loadRes("myGame/Prefab/UI/" + t, function (n) {
        if (!n) {
          o.UIs[t] = null;
          return void console.error("要显示的界面预制不存在：", t);
        }
        var i = cc.instantiate(n);
        o.node.getChildByName(t).addChild(i);
        var r = i.getComponent(cc.Widget);
        r && r.updateAlignment();
        var a = i.getComponent(cc.Layout);
        a && a.updateLayout();
        var s = i.getComponent(t);
        s.init();
        o.UIs[t] = s;
        o.showUI(t, e);
      });
    }
  };
  _ctor.exitUI = function (t) {
    var e = this.UIs[t];
    if (e) {
      e.hide();
      a.default.emit($GameEventType.EventType.UIEvent.exited, t);
    }
  };
  return _ctor;
}();
exports.default = def_UIManager;